﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using MediaController.Subs;
using MediaController.Subs.Provider;

namespace Tester
{
    public partial class Form1 : Form
    {
        private readonly SratimProvider _sratimProvider = new SratimProvider();
        private int NoSubtitleMachFoundcounter;
        private int NoTitleMachFoundcounter;

        public Form1()
        {
            InitializeComponent();

            _sratimProvider.NoSubtitleMachFound += sratimProvider_NoSubtitleMachFound;
            _sratimProvider.NoTitleMachFound += sratimProvider_NoTitleMachFound;
            //_sratimProvider.SearchedFileChanged += _sratimProvider_ProgressChanged;
            //var autoExtract = new AutoExtract();
            //autoExtract.Start(@"D:\Downloads\New folder");
        }

        private void _sratimProvider_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            backgroundWorker1.ReportProgress(e.ProgressPercentage, e.UserState);
        }

        private void sratimProvider_NoTitleMachFound(object arg1, NoMatchTitleFoundEventArgs arg2)
        {
            NoTitleMachFoundcounter++;
            //throw new System.NotImplementedException();
        }

        private void sratimProvider_NoSubtitleMachFound(object arg1, NoMatchSubtitleFoundEventArgs arg2)
        {
            NoSubtitleMachFoundcounter++;
            //throw new System.NotImplementedException();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //_sratimProvider.DownloadSubtitle(new TitlesFolderInfo(textBox1.Text));
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.ProgressPercentage != 0)
            {
                progressBar1.Text = e.ProgressPercentage.ToString();
                progressBar1.Value = e.ProgressPercentage;
                label1.Text = e.UserState + "    " + e.ProgressPercentage + "%";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            MessageBox.Show(string.Format("{0} {1} {2}", NoTitleMachFoundcounter
                                          , Environment.NewLine, NoSubtitleMachFoundcounter));
        }
    }
}